<?php
namespace app\service;

use think\facade\Db;

class parkingService{
    //查询当前登录账号信息
    public function adminIdInfo($id){
        return Db::name('admin')->where('id',$id)->find();
    }
    //查询总物业账号下面的所有分物业
    public function propertyService($service){
        return DB::name('property')->where('service_id',$service)->column('id');
    }
    //根据条件查找区域数据
    public function communityIdList($where){
        return Db::name('community')->where($where)->order('id desc')->column('id');
    }
    //根据条件查找停车场信息
    public function parkingList($where){
        return Db::name('parkinglotinfo')->where($where)->order('id desc')->select();
    }

    //查询区域名称
    public function communityIdName($id){
        return Db::name('community')->where('id',$id)->value('name');
    }
    //根据条件查找区域数据
    public function communityList($where){
        return Db::name('community')->where($where)->order('id desc')->select();
    }
    //判断停车场名称是否重复
    public function parkingName($parking_name){
        return Db::name('parkinglotinfo')->where('parkingName',$parking_name)->find();
    }
    //添加停车场信息
    public function parkingAdd($data){
        return Db::name('parkinglotinfo')->insertGetId($data);
    }
    //查询指定ID停车场信息
    public function parkingId($id){
        return Db::name('parkinglotinfo')->where('id',$id)->find();
    }
    //修改指定ID停车场信息
    public function parkingEdit($data){
        return Db::name('parkinglotinfo')->update($data);
    }
    //删除指定ID停车场信息
    public function parkingDel($id){
        return Db::name('parkinglotinfo')->delete($id);
    }
    //根据区域ID查询物业token
    public function propertyToken($id){
        //查询物业ID
        $propertyid = Db::name('community')->where('id',$id)->value('property_id');
        //根据物业ID查询token
        return Db::name('property')->where('id',$propertyid)->value('accredit');
    }

    //----------------------------------------------------收费规则-----------------------------------------------------
    //根据区域ID查询收费规则
    public function standardInfo($parkingid){
        return Db::name('standard')->where('parking_id', 'in',$parkingid)->order('id desc')->select();
    }
    //根据停车场ID查询停车场名称
    public function parkingIdInfo($parkingid){
        return Db::name('parkinglotinfo')->where('out_parking_id',$parkingid)->find();
    }
    //添加收费规则
    public function standardAdd($data){
        return Db::name('standard')->insert($data);
    }
    //根据ID查询收费规则
    public function standardId($id){
        return Db::name('standard')->where('id',$id)->find();
    }
    //修改收费规则
    public function standardEdit($data){
        return Db::name('standard')->update($data);
    }
    //删除收费规则
    public function standardDel($id){
        return Db::name('standard')->delete($id);
    }
    //----------------------------------------------------进出设备-----------------------------------------------------
    //根据区域ID查询设备
    public function systemInfo($parkingid){
        return Db::name('system')->where('parking_id', 'in' ,$parkingid)->order('id desc')->select();
    }
    //判断设备是否重复
    public function systemName($system){
        return Db::name('system')->where('system',$system)->find();
    }
    //添加设备
    public function systemAdd($data){
        return Db::name('system')->insert($data);
    }
    //根据ID查询设备
    public function systemId($id){
        return Db::name('system')->where('id',$id)->find();
    }
    //修改设备
    public function systemEdit($data){
        return Db::name('system')->update($data);
    }
    //删除设备
    public function systemDel($id){
        return Db::name('system')->delete($id);
    }
    //查询账号
    public function propertyInfo($communityid){
        $property = Db::name('community')->where('id',$communityid)->value('property_id');
        return Db::name('property')->where('id',$property)->find();
    }
    //----------------------------------------------------停车记录-----------------------------------------------------
    //多条件查询停车记录
    public function recordWhereList($out_parking_id,$page,$where){
        return Db::name('record')->where('out_parking_id','in',$out_parking_id)->where($where)->order('id desc')->paginate(100, false, [
            'page'  =>  $page,
            'query' =>  $where
        ]);
    }
    //查询停车记录总条数
    public function recordWhereNumber($out_parking_id,$where){
        return Db::name('record')->where('out_parking_id','in',$out_parking_id)->where($where)->select();
    }
	//----------------------------------------------------开闸记录-----------------------------------------------------
    //多条件查询
    public function openWhereList($out_parking_id,$where,$start_time,$end_time,$page){
        $where_old = $where;
        $where['start_time'] = $start_time;
        $where['end_time'] = $end_time;
        return Db::name('open_reason')->where('out_parking_id','in',$out_parking_id)->where('open_time','>=',$start_time)->where('open_time','<=',$end_time)->where($where_old)->order('id desc')->paginate(100,false,[
            'page' => $page,
            'query' => $where
        ]);

    }
    //----------------------------------------------------打印机配置-----------------------------------------------------
    //添加打印机
    public function printAdd($data){
        return Db::name('system')->update($data);
    }
}